package com.sfh.dog.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

import com.sfh.dog.adapter.ReviewAdapter;
import com.sfh.dog.entity.Daily;
import com.sfh.dog.entity.Review;
import com.sfh.dog.ui.base.BaseActivity;
import com.sfh.dog.util.NetWorkHelper;

/**
 * 详情
 * 
 * @version [版本号2014-4-1]
 */
public abstract class ADailyActivity extends BaseActivity
{
    public int page = 0;
    
    public List<Review> reviews;
    
    public Daily entity;
    
    public ReviewAdapter mReviewAdapter;
    
    public static final String KEY = "key";
    
    public abstract void setAdapter();
    
    public abstract void onLoadingComplete();
    
    

    public void init()
    {
        entity = (Daily)getIntent().getSerializableExtra(KEY);
        reviews = new ArrayList<Review>();
        setAdapter();
    }
    
    /** 获取日志留言 */
    public void getReview()
    {
        
        if (NetWorkHelper.isNetworkAvailable(getApplicationContext()))
        {
            BmobQuery<Review> query = new BmobQuery<Review>();
            query.setSkip(10 * page);
            query.setLimit(10 * (page + 1));
            query.order("-createdAt");
            query.findObjects(this, new FindListener<Review>()
            {
                
                @Override
                public void onSuccess(List<Review> arg0)
                {
                    if (page == 0)
                    {
                        reviews.clear();
                    }
                    reviews.addAll(arg0);
                    mReviewAdapter.notifyDataSetChanged();
                    onLoadingComplete();
                    
                }
                
                @Override
                public void onError(int arg0, String arg1)
                {
                    onLoadingComplete();
                }
            });
        }
        else
        {
            onLoadingComplete();
        }
    }
    
}
